const express = require('express');
const {
	Msg,
	Paths
} = require('../tools/message.js');
const mysqlObj = require('../model/mysql.class.js');
const router = express.Router();


router.get('/secondcate', async (req, res) => {
	let firstid = req.query.firstid ? req.query.firstid : '';
	let idreg = /^\d{1,4}$/;
	firstid = parseInt(firstid)
	console.log(firstid);
	if (firstid = '') {
		res.send(Msg(500, '一级类别不能为空'));
		return;
	} else if (!idreg.test(firstid)) {
		console.log(idreg.test(firstid),12345);
		res.send(Msg(500, '一级类别id的值只能为数字'));
		return;
	}

	let sql = `select second_id,second_name from category_second where first_id='${firstid}'`;
	let [err, arr] = await mysqlObj.exec(sql);
	if (err) {
		res.send(Msg(500, '二级类别查询失败'))
	} else {
		res.send(Msg(200, '二级类别查询成功', arr))
	}
})



module.exports = router;
